package cn.flying.cloud.common.controller;

import javax.annotation.Resource;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.bo.UserInfo;
import cn.flying.cloud.base.common.constants.Constants;
import cn.flying.cloud.base.common.utils.Ft;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.system.dict.service.SysDictDataService;
import cn.flying.cloud.system.resource.service.SysResInfoService;
import cn.flying.cloud.system.user.service.SysUserInfoService;
import cn.flying.cloud.system.vo.MenuInfoVO;

/**
 * 页面公共请求 前端控制器
 *
 * @author: admin
 * @date: 2025年03月03日 21:23
 * @version: 1.0
 */
@RestController
@RequestMapping("/")
public class CommonController {

    @Resource
    private SysDictDataService sysDictDataService;
    @Resource
    private SysUserInfoService sysUserInfoService;
    @Resource
    private SysResInfoService sysResInfoService;

    /**
     * 获取用户信息
     *
     * @return
     */
    @PostMapping("getUserInfo")
    public Rt getUserInfo() {
        String username = (String) Ft.ThreadLocal.get(Constants.USER_NAME);
        UserInfo authInfo = sysUserInfoService.getUserAuthInfo(username, "username");
        //不要返回密码信息
        authInfo.setPassword(null);
        return Rt.success(authInfo);
    }

    /**
     * 获取用户菜单路由信息
     *
     * @return
     */
    @GetMapping("getRouters")
    public Rt getRouters() {
        String userId = Ft.Local.UserId();
        String tenantId = Ft.Local.TenantId();
        List<MenuInfoVO> menuInfos = sysResInfoService.getMenuInfos(userId, tenantId);
        return Rt.success(menuInfos);
    }

    /**
     * 获取字典信息
     *
     * @return
     */
    @PostMapping("/system/dict")
    public Rt<?> dict(String type) {
        return Rt.success(sysDictDataService.getCodeList(type));
    }

}
